<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id="btn">请求数据</button>
    <ul id="ul"></ul>

    <script>
        let btn = document.getElementById('btn')
        let ul = document.getElementById('ul')

        // ajax
        function getData() {
            let xhr = new XMLHttpRequest();
            xhr.open('GET', 'https://mock.mengxuegu.com/mock/65a91543c4cd67421b34c898/movie/movieList', true)
            xhr.send();
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    console.log(JSON.parse(xhr.responseText));
                    const movieList = JSON.parse(xhr.responseText).movieList
                    renderLi(movieList)
                }
            }
        }

        function renderLi(arr) {
            arr.forEach(item => {
                let li = document.createElement('li');
                li.innerText = item.nm
                ul.appendChild(li);
            });
        }

        btn.addEventListener("click", () => {
            getData()
        })
    </script>

</body>

</html>